/**
 * @File AssetClassController.java
 * @author Dhruv
 * @Version 1.0
 * @Date April 18, 2013
 * 
 * Copyright (c) 2011 EdRP, Dayalbagh Educational Institute.
 * All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this  list of conditions and the following disclaimer.
 *
 * Redistribution in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL ETRG OR ITS CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL,SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Contributors: Members of EdRP, Dayalbagh Educational Institute
 */
package in.ac.dei.edrp.generalLedger.assetClass;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Controller;

import flex.messaging.FlexContext;
import flex.messaging.FlexSession;

@Controller
@RemotingDestination("assetClassServiceDestination")
public class AssetClassController
{
	@Autowired
	@Qualifier("AssetClassDaoImpl")
	private AssetClassDao assetClassDao;
	
	
	public List<AssetClassBean> getAllAssetClass(String flag)
	{
		AssetClassBean bean = new AssetClassBean();
		FlexSession session = FlexContext.getFlexSession();
		bean.setOrganizationId(session.getAttribute("universityCode").toString());
		List<AssetClassBean> list = assetClassDao.getAllAssetClass(bean,flag);
		return list;		
	}
	
	
	/** 
	 * This function is used to get the required fields (assetClassCode,assetClassName,universityCode,creatorId) input by the user
	 * in the text fields shown on the UI.
	 */
	public String setAssetClasses(Map<String, String> obj)
	{
		String str = "";
		FlexSession session = FlexContext.getFlexSession();
		AssetClassBean input = new AssetClassBean();
		input.setAssetClassCode(obj.get("assetClassCode"));
		input.setAssetClassName(obj.get("assetClassName"));
		input.setOrganizationId(session.getAttribute("universityCode").toString());
		input.setUserId(session.getAttribute("creatorId").toString());
		str = assetClassDao.setAssetClasses(input);
		
		return str;
	
	}
	
	
	public List<AssetClassBean> getAssetClassCodeClassName() 
	{    
		 FlexSession session = FlexContext.getFlexSession(); 
		 List<AssetClassBean> list = new ArrayList<AssetClassBean>();
	     AssetClassBean input = new AssetClassBean();
	     input.setOrganizationId(session.getAttribute("universityCode").toString());
	     list = assetClassDao.getAssetClassCodeClassName(input);
	     return list;	
	     
	}
	/**
	 * setAssetSubClasses method is used to get the required fields (assetSubClassCode, assetSubClassName, assetClassCode, assetClassName
	 * universityCode,creatorId, flag, oldAssetSubClassCode) input by the user to the server side. oldAssetsubClassCode is used to maintain
	 * the subClassCode we want to update.It is used for the update query in the AssetClass.xml file, in the WHERE clause. 
	 * 
	 * 
	 */
	public String setAssetSubClasses(Map<String, String> obj)
	{
		String str = "";
		FlexSession session = FlexContext.getFlexSession();
		AssetClassBean input = new AssetClassBean();
		input.setAssetSubClassCode(obj.get("assetSubClassCode"));
		input.setAssetSubClassName(obj.get("assetSubClassName"));
		input.setAssetClassCode(obj.get("assetClassCode"));
		input.setAssetClassName(obj.get("assetClassName"));
		input.setOrganizationId(session.getAttribute("universityCode").toString());
		input.setUserId(session.getAttribute("creatorId").toString());
		input.setFlag(obj.get("flag"));
		input.setOldAssetSubClassCode(obj.get("oldAssetSubClassCode"));
		str = assetClassDao.setAssetSubClasses(input);
		return str;
	}
	
	public String deleteAssetClasses(Map<String, String> obj)
	{
		String str = "";
		FlexSession session = FlexContext.getFlexSession();
		AssetClassBean input= new AssetClassBean();
		input.setAssetClassCode(obj.get("assetClassCode"));
		input.setOrganizationId(session.getAttribute("universityCode").toString());
	    str = assetClassDao.deleteAssetClasses(input);
	    return str;
	    
	    }
	
	
	public String deleteAssetSubClasses(Map<String, String> obj)
	{
		String str = "";
		FlexSession session = FlexContext.getFlexSession();
		AssetClassBean input= new AssetClassBean();
		input.setAssetClassCode(obj.get("assetClassCode"));
		input.setAssetSubClassCode(obj.get("assetSubClassCode"));
		input.setOrganizationId(session.getAttribute("universityCode").toString());
	    str = assetClassDao.deleteAssetSubClasses(input);
	    return str;
    }
}
